#!/usr/bin/env bash
# vim: fdm=marker fmr=[[[,]]] cms=\ #%s

(( BIT_OF_CHAR=8 ))
(( MSG_SIZE_SIZE=6 ))
(( MSG_SIZE=1024*1024 ))

wrap_size()
{ #[[[
    local msg=$1
    if (( ${#msg} > MSG_SIZE-MSG_SIZE_SIZE ))
    then
        echo
        return 1
    fi
    msg=$(printf '%06X' ${#msg})${msg}
    echo $msg
} #]]]

unwrap_size()
{ #[[[
    local msg=$1
    if [[ -z $msg ]]
    then
        echo
        return 1
    fi
    if (( ${#msg} < MSG_SIZE_SIZE || ${#msg} > MSG_SIZE ))
    then
        echo
        return 1
    fi
    local size
    (( size=0x${msg:0:MSG_SIZE_SIZE} ))
    if (( ${#msg} != size+MSG_SIZE_SIZE ))
    then
        echo
        return 1
    fi
    echo ${msg:MSG_SIZE_SIZE}
} #]]]

process_is_running()
{ #[[[
    local proc=$1
    local res=$(ps -ef|grep -v grep|awk '$8 == "'$proc'" { print $2 }')
    if [[ -z $res ]]
    then
        echo 0
    else
        echo 1
    fi

} #]]]
